package routers

import (
	beego "github.com/beego/beego/v2/adapter"
	"github.com/beego/beego/v2/adapter/context"
	"github.com/beego/beego/v2/adapter/plugins/cors"
	"weiboxs.com/new_h_glasses/api"
)

func init() {
	//登录
	beego.Router("api/v1/login/dologin", &api.ApiLoginController{}, "Post:ApiDoLogin")
	//登录namespace
	loginNs := beego.NewNamespace("/api/v1",
		beego.NSBefore(func(ctx *context.Context) {
			return
		}),
		beego.NSRouter("login/check_auth", &api.ApiLoginController{}, "Post:ApiCheckAuth"), //验证是否有权限
		//档案
		beego.NSRouter("archives/index", &api.ApiArchivesController{}, "Post:ApiDataGrid"),      //获取档案列表
		beego.NSRouter("archives/edit", &api.ApiArchivesController{}, "Get,Post:ApiEdit"),       //保存修改档案
		beego.NSRouter("archives/delete", &api.ApiArchivesController{}, "Post:ApiDelete"),       //保存删除档案
		beego.NSRouter("archives/find", &api.ApiArchivesController{}, "Post:ApiViewOne"),        //保存获取单条
		beego.NSRouter("archives/findbyhid", &api.ApiArchivesController{}, "Post:ApiFindByHis"), //从HIS获取资料
		//验光
		beego.NSRouter("optometry/get_option", &api.ApiOptometryController{}, "Post:GetOption"),
		beego.NSRouter("optometry/datagrid", &api.ApiOptometryController{}, "Get,Post:ApiDataGrid"),
		beego.NSRouter("optometry/delete", &api.ApiOptometryController{}, "Post:ApiDelete"),
		beego.NSRouter("optometry/edit", &api.ApiOptometryController{}, "Post:ApiEdit"),
		beego.NSRouter("optometry/edit_single", &api.ApiOptometryController{}, "Post:ApiEditSingle"),
		beego.NSRouter("optometry/view/?:id", &api.ApiOptometryController{}, "Post,Get:ApiView"),
		beego.NSRouter("optometry/view_one", &api.ApiOptometryController{}, "Post:ApiViewOne"),
		//库存
		beego.NSRouter("inventory/inventory", &api.ApiInventoryController{}, "Post,Get:ApiInventory"), //erp 库存产品
		//销售
		beego.NSRouter("retail/datagrid", &api.ApiRetailController{}, "Post:ApiDataGrid"), //销售列表
		beego.NSRouter("retail/addsalse", &api.ApiRetailController{}, "Post:ApiAddSales"), //保存销售信息
		beego.NSRouter("retail/delete", &api.ApiRetailController{}, "Post:ApiDelete"),     //保存销售信息
		beego.NSRouter("retail/view", &api.ApiRetailController{}, "Post:ApiView"),         //查看销售信息
		beego.NSRouter("retail/send_sms", &api.ApiRetailController{}, "Post:ApiSendSms"),  //发送取镜通知
	)
	beego.AddNamespace(loginNs)

	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
		AllowCredentials: true,
	}))

	beego.Router("/api/wechat/message", &api.ApiWechatController{}, "Get:Message")         //微信消息显示
	beego.Router("/api/wechat/js-sdk", &api.ApiWechatController{}, "Post:JsSdk")           //微信JSSDK
	beego.Router("/api/wechat/index", &api.ApiWechatController{}, "*:WechatIndex")         //微信推送接口
	beego.Router("/api/wechat/optometry", &api.ApiWechatController{}, "Get:ShowOptometry") //微信展示验光数据

	beego.Router("/api/visual", &api.SubjectiveController{}, "Post:Subjective")          //视力表
	beego.Router("/api/save_archives", &api.SubjectiveController{}, "Post:SaveArchives") //电脑验光仪
}
